package org.dromara.germbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.germbank.domain.BusCaseBlog;
import org.dromara.germbank.domain.BusPartnerClinic;
import org.dromara.germbank.domain.bo.BusCaseBlogBo;
import org.dromara.germbank.domain.bo.BusPartnerClinicBo;
import org.dromara.germbank.domain.vo.BusCaseBlogVo;
import org.dromara.germbank.domain.vo.BusPartnerClinicVo;
import org.dromara.germbank.mapper.BusCaseBlogMapper;
import org.dromara.germbank.service.BusCaseBlogService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Blog 实施类
 *
 * @author congxing
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class BusCaseBlogServiceImpl implements BusCaseBlogService {

    private final BusCaseBlogMapper busCaseBlogMapper;

    @Override
    public TableDataInfo<BusCaseBlogVo> queryPageList(BusCaseBlogBo bo, PageQuery pageQuery) {
        Page<BusCaseBlogVo> page = busCaseBlogMapper.queryPageList(pageQuery.build(),this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    @Override
    public boolean checkBlogNameUnique(BusCaseBlogBo bo) {
        return false;
    }

    @Override
    public int insertBlog(BusCaseBlogBo bo) {
        return 0;
    }

    @Override
    public void updateBlogData(BusCaseBlogBo bo) {

    }

    @Override
    public void deleteBlogCodesDataByIds(List<Long> bo) {

    }

    // 分页查询条件
    private Wrapper<BusCaseBlog> buildQueryWrapper(BusCaseBlogBo bo) {
        return Wrappers.<BusCaseBlog>lambdaQuery()
            // 逻辑删除字段（固定条件）
            .eq(BusCaseBlog::getDelFlag, SystemConstants.NORMAL)

            // 文章标题（模糊）
            .like(StringUtils.isNotBlank(bo.getTitle()),
                BusCaseBlog::getTitle, bo.getTitle())

            // 文章分类（精确）
            .eq(StringUtils.isNotBlank(bo.getCategory()),
                BusCaseBlog::getCategory, bo.getCategory())

            // 文章作者（模糊）
            .like(StringUtils.isNotBlank(bo.getAuthor()),
                BusCaseBlog::getAuthor, bo.getAuthor())

            // 排序：置顶倒序 + 权重倒序 + 发布时间倒序
            .orderByDesc(BusCaseBlog::getIsTop)
            .orderByDesc(BusCaseBlog::getSortWeight)
            .orderByDesc(BusCaseBlog::getPublishAt);
    }

}
